package com.tm.springbootoss.controller;

import com.tm.springbootoss.util.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


import java.io.IOException;

/**
 * 2024/6/26 Cjj OSS图片上传
 */
@RestController
@RequestMapping("api/file/")
public class FileUploadController<R> {
    @PostMapping("uploadimg")
    public R upload(MultipartFile file) throws IOException {
        //1.验证是否有文件
        if (!file.isEmpty()) {
            //2.获取文件名
            String fn = file.getOriginalFilename();
            //3.获取文件内容
            byte[] data = file.getBytes();
            //4.存储的阿里云oss中
            AliOssUtil.upload(data, fn);
        }
        return upload(file);
    }
}
